# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=seatd
pkgver=0.8.0
pkgrel=0
pkgdesc="Minimal seat management daemon"
url="https://sr.ht/~kennylevinsen/seatd/"
license="MIT"
arch="all"
options="suid"  # needed for seatd-launch
pkggroups="seat"
install="$pkgname.pre-install $pkgname.post-install $pkgname.post-upgrade"
makedepends="meson scdoc elogind-dev linux-headers"
subpackages="libseat:libs libseat-dev $pkgname-launch $pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://git.sr.ht/~kennylevinsen/seatd/archive/$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	"

# secfixes:
#   0.6.2-r0:
#     - CVE-2021-41387

build() {
	if [ "$CARCH" = 'ppc64le' ]; then
		# https://todo.sr.ht/~kennylevinsen/seatd/10
		# https://www.openwall.com/lists/musl/2020/01/20/3
		export CFLAGS="$CFLAGS -Wno-error=overflow"
	fi

	abuild-meson \
		-Dlibseat-logind=elogind \
		-Dman-pages=enabled \
		. output

	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	chmod u+s "$pkgdir"/usr/bin/seatd-launch

	install -Dm755 "$srcdir"/seatd.initd "$pkgdir"/etc/init.d/seatd
	install -Dm644 "$srcdir"/seatd.confd "$pkgdir"/etc/conf.d/seatd
}

libs() {
	default_libs
	pkgdesc="Universal seat management library"
}

dev() {
	default_dev
	pkgdesc="Universal seat management library (development files)"
}

launch() {
	pkgdesc="Command to start a process with its own seatd instance (SUID binary)"
	depends="$pkgname"

	amove usr/bin/seatd-launch
}

sha512sums="
93b1e5c170564ce9654e4df9985af95cb505274b36e950998bb1f16803d2d46712140eded2bdd8d5e85aec62070afd9c224184276d79a0ff0813408dfc472db7  seatd-0.8.0.tar.gz
3b5baa320c376d136e2c933df5f12022fd12a46d319b95229a89f30ed7b9c3b1dba39c306c931aa25faf381b98b7a241b9693e22c9554022275903915a350c96  seatd.initd
1ee755b462455fb20ee2f56b8d1a0f3a26eb9aed34eb6126e322243f9288b23577aff40e5a2c02449f349282af79eafd232b9e77cd196daa92ee8a9fcae2ec16  seatd.confd
"
